home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre3.z / postgre3 / src / lib / H / utils / module.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  7.2 KB  |  237 lines

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *    module.h
  4.  *
  5.  *   DESCRIPTION
  6.  *    this file contains general "module" stuff  that used to be
  7.  *    spread out between the following files:
  8.  *
  9.  *    enbl.h            module enable stuff
  10.  *    trace.h            module trace stuff
  11.  *
  12.  *   NOTES
  13.  *    some more stuff may be moved here.
  14.  *
  15.  *   IDENTIFICATION
  16.  *    $Header: /private/postgres/src/lib/H/utils/RCS/module.h,v 1.2 1991/11/11 19:32:17 mer Exp $
  17.  * ----------------------------------------------------------------
  18.  */
  19. #ifndef ModuleHIncluded
  20. #define ModuleHIncluded 1    /* include once only */
  21.  
  22. #include "tmp/c.h"
  23. #include "tmp/simplelists.h"
  24.  
  25. /* ----------------
  26.  *    enbl.h
  27.  * ----------------
  28.  */
  29. /*
  30.  * enbl.h --
  31.  *    POSTGRES module enable and disable support code.
  32.  *
  33.  * Identification:
  34.  *    $Header: /private/postgres/src/lib/H/utils/RCS/module.h,v 1.2 1991/11/11 19:32:17 mer Exp $
  35.  */
  36.  
  37. #ifndef    EnblIncluded        /* Include this file only once */
  38. #define EnblIncluded    1
  39.  
  40. #define ENBL_H    "$Header: /private/postgres/src/lib/H/utils/RCS/module.h,v 1.2 1991/11/11 19:32:17 mer Exp $"
  41.  
  42. /*
  43.  * BypassEnable --
  44.  *    False iff enable/disable processing is required given on and "*countP."
  45.  *
  46.  * Note:
  47.  *    As a side-effect, *countP is modified.  It should be 0 initially.
  48.  *
  49.  * Exceptions:
  50.  *    BadState if called with pointer to value 0 and false.
  51.  *    BadArg if "countP" is invalid pointer.
  52.  *    BadArg if on is invalid.
  53.  */
  54. extern
  55. bool
  56. BypassEnable ARGS((
  57.     Count    *enableCountInOutP,
  58.     bool    on
  59. ));
  60.  
  61. #endif    /* !defined(EnblIncluded) */
  62.  
  63. /* ----------------
  64.  *    trace.h
  65.  * ----------------
  66.  */
  67. /*
  68.  *  TRACE.H
  69.  *
  70.  *  $Header: /private/postgres/src/lib/H/utils/RCS/module.h,v 1.2 1991/11/11 19:32:17 mer Exp $
  71.  *
  72.  *  Trace Hierarchy:
  73.  *    The TraceTree[] array in trace.c holds the global trace hierarchy.
  74.  *    Up to two parents may be specified for every trace name.  Each
  75.  *    source module using the trace functions may declare any number
  76.  *    of trace variables optionally giving them zero, one, or two parents:
  77.  *  
  78.  *        DeclareTrace(ParserLex)
  79.  *        DeclareTraceParent(ParserLoops, Root)
  80.  *        DeclareTraceParents(ParserEval, Root, Parser)
  81.  *
  82.  *    The first declarations creates the trace variable 'ParserLex'
  83.  *    which has no parents.  The second creates another trace
  84.  *    variable 'ParserLoops' who has Root as a parent (Root is declared
  85.  *    in the TraceTree[] array in TRACE.C).  The third declares a
  86.  *    third trace variable with two parents.
  87.  *
  88.  *    Giving a trace variable one or more parents means that if tracing
  89.  *    is turned on for either parent, it is automatically turned on for
  90.  *    the variable.  This is recursive... a tree of trace variables may
  91.  *    be specified in the TraceTree[] array in TRACE.C
  92.  *
  93.  *    One can declare a limited two level tree locally (private to the
  94.  *    module).  e.g.:
  95.  *    
  96.  *        DeclareTrace(Foo)
  97.  *        DeclareTraceParent(Bar1, Foo)
  98.  *        DeclareTraceParent(Bar2, Foo)
  99.  *
  100.  *    Foo may not have any parents.
  101.  *
  102.  *    Trace variables are enabled by setting enviroment variables to
  103.  *    the trace level desired.  TRACE_<tracename>.  For example:
  104.  *
  105.  *        % setenv TRACE_Foo 1
  106.  *
  107.  *    If the enviroment variable exists but has no value or is 0, i.e.:
  108.  *
  109.  *        % setenv TRACE_Foo        or
  110.  *        % setenv TRACE_Foo 0
  111.  *
  112.  *    The trace level is set to 1.  Any number of TRACE_ enviroment
  113.  *    variables may be set, enabling those specific trace variables.
  114.  *
  115.  *    Trace variables may be tested with the Traced() macro.
  116.  *    Trace messages may be generated with TraceMsg*() macros.  Since
  117.  *    a level is associated with each trace variable, only messages at
  118.  *    or below the current trace level will be output.  
  119.  *
  120.  *    Messages at trace level 0 are always output.  The TraceMsg*() calls
  121.  *    output messages and level 1 while the TraceMsgAt*() calls output
  122.  *    messages at the specified level.
  123.  *
  124.  *    Variations of the Declare*() macros exist allowing you to 
  125.  *    assign a stream other than the default to the variable.  The
  126.  *    stream directs where the output will go (see enum below).
  127.  *
  128.  *    SEE TEST PROGRAM FOR EXAMPLES (test/testtrace.c)
  129.  */
  130.  
  131. #ifndef TRACE_H
  132. #define TRACE_H
  133.  
  134. #define TraceBlock struct _TraceBlock
  135. #define TraceStack struct _TraceStack
  136.  
  137. #define TBF_INITIALIZED        0x01
  138. #define TBF_FAULT        0x02
  139.  
  140. typedef enum TraceStream { 
  141.     DefaultStream, LogStream, InstallationStream, DBStream, ConsoleStream,
  142.     FrontendStream, PostmasterStream, AuxStream
  143. } TraceStream;
  144.  
  145. TraceBlock {
  146.     char   *Module;    /* trace module            */
  147.     char   *Name;    /* trace variable name            */
  148.     char   *Parent1;    /* name of parent / NULL        */
  149.     char   *Parent2;    /* name of parent / NULL        */
  150.     long    Level;    /* trace level, 0 = disabled    */
  151.     TraceStream Stream;
  152.     uint32  Flags;    /* trace flags                */
  153.     SLNode  Node;    /* link node for trace.c    */
  154. };
  155.  
  156. TraceStack {
  157.     TraceBlock *Tb;
  158.     int    LineNo;    /* line in module        */
  159.     char   *Text;    /* display this text        */
  160.     SLNode  Node;    /* link node for trace.c    */
  161. };
  162.  
  163. #define TNAME(name)    CppConcat(Trace_,name)
  164.  
  165. #define Traced(name)        \
  166.     (TraceInitialize(&TNAME(name)), (TNAME(name).Level > 0))
  167.  
  168. #define GetTraceLevel(name)     \
  169.     (TraceInitialize(&TNAME(name)), (TNAME(name).Level))
  170.  
  171. #define DeclareTraceTo(stream,name) \
  172.     static TraceBlock TNAME(name) = \
  173.     { __FILE__, CppAsString(name) }
  174.  
  175. #define DeclareTraceParentTo(stream,name,parent)    \
  176.     static TraceBlock TNAME(name) = \
  177.     { __FILE__, CppAsString(name),CppAsString(parent) }
  178.  
  179. #define DeclareTraceParentsTo(stream,name,p1,p2)      \
  180.     static TraceBlock TNAME(name) = \
  181.     { __FILE__, CppAsString(name), CppAsString(p1), CppAsString(p2) }
  182.  
  183. #define DeclareTrace(name)        \
  184.     DeclareTraceTo(DefaultStream,name)
  185.  
  186. #define DeclareTraceParent(name,parent)    \
  187.     DeclareTraceParentTo(DefaultStream,name,parent)
  188.  
  189. #define DeclareTraceParents(name,p1,p2) \
  190.     DeclareTraceParentsTo(DefaultStream,name,p1,p2)
  191.  
  192.  
  193. #define TraceMsg0(tb,mc)            _TraceMsg(&TNAME(tb),1,0,mc)
  194. #define TraceMsg1(tb,mc,m1)            _TraceMsg(&TNAME(tb),1,1,mc,m1)
  195. #define TraceMsg2(tb,mc,m1,m2)        _TraceMsg(&TNAME(tb),1,2,mc,m1,m2)
  196.  
  197. #define TraceMsgSub0(tb,lv,mc)        _TraceMsg(&TNAME(tb),lv,0,mc)
  198. #define TraceMsgSub1(tb,lv,mc,m1)    _TraceMsg(&TNAME(tb),lv,1,mc,m1)
  199. #define TraceMsgSub2(tb,lv,mc,m1,m2)      _TraceMsg(&TNAME(tb),lv,2,mc,m1,m2)
  200.  
  201. #define TraceOn(tb,level)        SetTraceLevel(TNAME(tb).Name,level)
  202. #define TraceOff(tb)            SetTraceLevel(TNAME(tb).Name,0)
  203.  
  204. /*
  205.  *  Subroutine Tracing
  206.  */
  207.  
  208. #define TracePush(tb, str)        _TracePush(&TNAME(tb), __LINE__, str)
  209. #define TracePop(tb)            _TracePop(&TNAME(tb), __LINE__, "")
  210. #define TracePop1(tb, str)        _TracePop(&TNAME(tb), __LINE__, str)
  211. #define TraceReset(tb, str)        _TraceReset(&TNAME(tb), __LINE__, str)
  212. #define TraceDump()            _TraceDump()
  213.  
  214. void EnableTrace ARGS((int enable ));
  215. int _TraceMsg ARGS((TraceBlock *tb , int level , int nargs , Pointer arg0 ));
  216. void TraceInitialize ARGS((TraceBlock *tb ));
  217. int RemoveHeadTailSpaces ARGS((char **str ));
  218. int InitializeTheGlobalArray ARGS((void ));
  219. void SetTraceLevel ARGS((char *traceName , int level ));
  220. bool TraceFileName ARGS((char *fileName ));
  221. void _TracePush ARGS((TraceBlock *tb , int lineno , char *str ));
  222. void _TracePop ARGS((TraceBlock *tb , int lineno , char *str ));
  223. void _TraceReset ARGS((TraceBlock *tb , int lineno , char *str ));
  224. void _TraceDump ARGS((void ));
  225. char *TailName ARGS((char *str ));
  226. Pointer TraceAlloc ARGS((int bytes ));
  227. void TraceFree ARGS((Pointer ptr , int bytes ));
  228.  
  229. #endif TRACE_H
  230.  
  231.  
  232. /* ----------------
  233.  *    end of module.h
  234.  * ----------------
  235.  */
  236. #endif ModuleHIncluded
  237.